package com.evl.wxpay.util;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import com.evl.dictionaryConfig.DictConfig;
import com.evl.dictionaryConfig.DictConst;

public class WXPayConfigImpl extends WXPayConfig {
	
	private static WXPayConfigImpl INSTANCE;
    private byte[] certData;

	public static WXPayConfigImpl getInstance() throws Exception {
		if (INSTANCE == null) {
			synchronized (WXPayConfigImpl.class) {
				if (INSTANCE == null) {
					INSTANCE = new WXPayConfigImpl();
				}
			}
		}
		return INSTANCE;
	}

	@Override
	protected String getAppID() {
		return  DictConfig.getKey(DictConst.wx_appId);
	}

	protected String getMchID() {
		return DictConfig.getKey(DictConst.wx_mchId);
	}

	protected String getKey() {
		return DictConfig.getKey(DictConst.wx_mch_secret);

	}

    public InputStream getCertStream() throws Exception {
    	 String certPath = DictConfig.getKey(DictConst.wx_cert_path);
         File file = new File(certPath);
         InputStream certStream = new FileInputStream(file);
         this.certData = new byte[(int) file.length()];
         certStream.read(this.certData);
         certStream.close();
	     ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
	     return certBis;
    }
    
	public int getHttpConnectTimeoutMs() {
		return 2000;
	}

	public int getHttpReadTimeoutMs() {
		return 10000;
	}

	protected IWXPayDomain getWXPayDomain() {
		return WXPayDomainSimpleImpl.instance();
	}

	public String getPrimaryDomain() {
		return "api.mch.weixin.qq.com";
	}

	public String getAlternateDomain() {
		return "api2.mch.weixin.qq.com";
	}

	@Override
	public int getReportWorkerNum() {
		return 1;
	}

	@Override
	public int getReportBatchSize() {
		return 2;
	}

}
